fix: use shlex tokenization to prevent false positive rm blocking#37
Open
bluzername wants to merge 1 commit into
Open
fix: use shlex tokenization to prevent false positive rm blocking#37bluzername wants to merge 1 commit into
bluzername wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
is_dangerous_rm_command()function inpre_tool_use.pyfalsely blocks safermcommands when directory names contain flag-like substrings. For example:The regex
r'\brm\s+.*-[a-z]*r'matches these because.*greedily eats the whole path, then-enrollmentmatches-[a-z]*r(therat the end of "enrollment").I hit this exact problem when Claude tried to clean up a temp directory with
-in the name and the hook kept blocking it.Fix
Replaced the regex approach with proper
shlex.split()tokenization. The new function:-r,-f,--recursive, etc.) from path operands--separator (everything after--is a path, not a flag)rm -rf(recursive + force together) andrm -rtargeting dangerous paths (/,~,.,..,$HOME)This means
rm /tmp/soft-hold-enrollmentis correctly recognized as having zero flags and just a path operand, so it passes.Test results
Closes #28